home *** CD-ROM | disk | FTP | other *** search
/ Aminet 30 / Aminet 30 (1999)(Schatztruhe)[!][Apr 1999].iso / Aminet / dev / lang / SmallEiffel.lha / SmallEiffel / lib_se / cecil_pool.e < prev    next >
Text File  |  1998-12-22  |  6KB  |  220 lines

  1. --          This file is part of SmallEiffel The GNU Eiffel Compiler.
  2. --          Copyright (C) 1994-98 LORIA - UHP - CRIN - INRIA - FRANCE
  3. --            Dominique COLNET and Suzanne COLLIN - colnet@loria.fr 
  4. --                       http://www.loria.fr/SmallEiffel
  5. -- SmallEiffel is  free  software;  you can  redistribute it and/or modify it 
  6. -- under the terms of the GNU General Public License as published by the Free
  7. -- Software  Foundation;  either  version  2, or (at your option)  any  later 
  8. -- version. SmallEiffel is distributed in the hope that it will be useful,but
  9. -- WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  10. -- or  FITNESS FOR A PARTICULAR PURPOSE.   See the GNU General Public License 
  11. -- for  more  details.  You  should  have  received a copy of the GNU General 
  12. -- Public  License  along  with  SmallEiffel;  see the file COPYING.  If not,
  13. -- write to the  Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  14. -- Boston, MA 02111-1307, USA.
  15. --
  16. class CECIL_POOL
  17.    --
  18.    -- Unique global object in charge of CECIL calls.
  19.    --
  20.  
  21. inherit GLOBALS;
  22.  
  23. feature {NONE}
  24.    
  25.    -- User's entry points from cecil file :
  26.    user_cecil_list: FIXED_ARRAY[RUN_FEATURE];
  27.    user_cecil_name: FIXED_ARRAY[STRING];
  28.  
  29.    user_path_h: STRING;
  30.  
  31. feature {SMALL_EIFFEL}
  32.  
  33.    fill_up is
  34.       local
  35.      t: TYPE;
  36.      rta: FIXED_ARRAY[TYPE];
  37.      fna: FIXED_ARRAY[FEATURE_NAME];
  38.      fn: FEATURE_NAME;
  39.      rf: RUN_FEATURE;
  40.      i: INTEGER;
  41.       do
  42.      -- For the user :
  43.      if run_control.cecil_path /= Void then
  44.         !!user_cecil_list.with_capacity(4);
  45.         !!user_cecil_name.with_capacity(4);
  46.         user_path_h := eiffel_parser.connect_to_cecil;
  47.         from
  48.            !!rta.with_capacity(4);
  49.            !!fna.with_capacity(4);
  50.         until
  51.            eiffel_parser.end_of_input
  52.         loop
  53.            user_cecil_name.add_last(eiffel_parser.parse_c_name);
  54.            rta.add_last(eiffel_parser.parse_run_type);
  55.            check
  56.           nb_errors = 0
  57.            end;
  58.            fna.add_last(eiffel_parser.parse_feature_name);
  59.            check
  60.           nb_errors = 0
  61.            end;
  62.         end;
  63.         eiffel_parser.disconnect;
  64.         echo.put_string("Loading cecil features.%N");
  65.         from
  66.            i := 0;
  67.         until
  68.            i > rta.upper
  69.         loop
  70.            t := rta.item(i).to_runnable(type_any);
  71.            fn := fna.item(i);
  72.            rf := t.run_class.get_feature(fn);
  73.            if rf = Void then
  74.           eh.add_position(fn.start_position);
  75.           fatal_error("Error while loading feature of cecil file.");
  76.            end;
  77.            user_cecil_list.add_last(rf);
  78.            switch_collection.update_with(rf);
  79.            i := i + 1;
  80.         end;
  81.      end;
  82.       end;
  83.  
  84. feature {C_PRETTY_PRINTER}
  85.  
  86.    c_define_users is
  87.       do
  88.      if user_cecil_list /= Void then
  89.         echo.put_string("Cecil (for user) :%N");
  90.         cpp.connect_cecil_out_h(user_path_h);
  91.         c_define_for_list(user_cecil_list,user_cecil_name);
  92.         cpp.disconnect_cecil_out_h;
  93.      end;
  94.       end;
  95.  
  96. feature {NONE}
  97.  
  98.    c_define_for_list(cecil_list: FIXED_ARRAY[RUN_FEATURE];
  99.              cecil_name: FIXED_ARRAY[STRING]) is
  100.       require
  101.      cecil_name.count = cecil_list.count
  102.       local
  103.      i: INTEGER;
  104.       do
  105.      from
  106.         i := cecil_list.upper;
  107.      until
  108.         i < 0
  109.      loop
  110.         c_define_for(cecil_name.item(i),cecil_list.item(i));
  111.         i := i - 1;
  112.      end;
  113.       end;
  114.  
  115. feature {NONE}
  116.    
  117.    c_define_for(c_name: STRING; rf: RUN_FEATURE) is
  118.       require
  119.      not c_name.empty;
  120.      rf /= Void
  121.       local
  122.      rfct, rfrt: TYPE;
  123.      rfargs: FORMAL_ARG_LIST;
  124.       do
  125.      rfct := rf.current_type;
  126.      rfrt := rf.result_type;
  127.      rfargs := rf.arguments; 
  128.      echo.put_string(rfct.run_time_mark);
  129.      echo.put_character('.');
  130.      echo.put_string(rf.name.to_string);
  131.      echo.put_character('%N');
  132.      -- (1) ------------------------- Define Cecil heading :
  133.      tmp_string.clear;
  134.      if rfrt /= Void then
  135.         rfrt.c_type_for_external_in(tmp_string);
  136.      else
  137.         tmp_string.append(fz_void);
  138.      end;
  139.      tmp_string.extend(' ');
  140.      tmp_string.append(c_name);
  141.      tmp_string.extend('(');
  142.      rfct.c_type_for_external_in(tmp_string);
  143.      tmp_string.extend(' ');
  144.      tmp_string.extend('C');
  145.      if rfargs /= Void then
  146.         tmp_string.extend(',');
  147.         rfargs.external_prototype_in(tmp_string);
  148.      end;
  149.      tmp_string.extend(')');
  150.      cpp.put_c_heading(tmp_string);
  151.      cpp.swap_on_c;
  152.      define_body_of(rf);
  153.       end;
  154.  
  155. feature {RUN_FEATURE}
  156.  
  157.    define_body_of(rf: RUN_FEATURE) is
  158.       local
  159.      rfct, rfrt: TYPE;
  160.      cecil_target: CECIL_TARGET;
  161.      cecil_arg_list: CECIL_ARG_LIST;
  162.      running: ARRAY[RUN_CLASS];
  163.       do
  164.      rfct := rf.current_type;
  165.      rfrt := rf.result_type;
  166.      running := rfct.run_class.running;
  167.      if running = Void then
  168.         eh.add_type(rfct," not created (type is not alive).");
  169.         eh.append("Empty Cecil function ");
  170.         eh.append(rfct.run_time_mark);
  171.         eh.append(rf.name.to_key);
  172.         eh.extend('.');
  173.         eh.print_as_warning;
  174.      end;
  175.      if run_control.no_check then
  176.         cpp.put_string(
  177.             "se_dump_stack ds={NULL,NULL,0,0,0,NULL,NULL};%N%
  178.         %ds.caller=se_dst;%N%
  179.         %se_dst=&ds;%N");
  180.      end;
  181.      if rfrt /= Void then
  182.         tmp_string.clear;
  183.         tmp_string.extend('{');
  184.         rfrt.c_type_for_external_in(tmp_string);
  185.         tmp_string.append(" R=");
  186.         cpp.put_string(tmp_string);
  187.      end;
  188.      !!cecil_target.make(rf);
  189.      if rf.arg_count > 0 then
  190.         !!cecil_arg_list.run_feature(rf);
  191.      end;
  192.      if rfct.is_expanded then
  193.         cpp.push_direct(rf,cecil_target,cecil_arg_list);
  194.         rf.mapping_c;
  195.         cpp.pop;
  196.      else
  197.         cpp.push_cpc(rf,running,cecil_target,cecil_arg_list);
  198.      end;
  199.      if rfrt /= Void then
  200.         cpp.put_string(fz_00);
  201.      end;
  202.      if run_control.no_check then
  203.         cpp.put_string("se_dst=ds.caller;%N");
  204.      end;
  205.      if rfrt /= Void then
  206.         cpp.put_string("return R;%N}%N");
  207.      end;
  208.      cpp.put_string(fz_12);
  209.       end;
  210.  
  211. feature {NONE}
  212.    
  213.    tmp_string: STRING is
  214.       once
  215.      !!Result.make(256);
  216.       end;
  217.  
  218. end -- CECIL_POOL
  219.  
  220.